<?php
/*
 * File: CheckToken.php
 * Created Time: 2023-11-14 3:50:15 pm
 * Author: Wang Yu Qiang (719404171@qq.com)
 * -----
 * Last Modified: 2023-11-14 3:50:29 pm
 * Modified By: Wang Yu Qiang (719404171@qq.com>)
 * -----
 * Copyright 2023 - 2023 Brainstorm Ltd, 成都睿創科技有限公司
 */
namespace App\Http\Middleware;

use Closure;
use App\Models\User;
use App\Http\Controllers\Controller;
class CheckToken extends Controller
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user = auth('api')->user();
        if(empty($user->user_id)){
            return response()->json(["status" => 400, "msg" => "No Operational Permission"]);
        }
        $data = new users();
        $res =  $data->where('user_id',$user->user_id)->where('user_status',1)->first();
        if($res){
            return $next($request);
        }else{
            return response()->json(["status" => 400, "msg" => "No Operational Permission"]);
        }
    }
}
